package org.openmrs;

public class AttributeAssignment extends BaseOpenmrsMetadata implements java.io.Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 761357612609237325L;
	
	private Attribute attribute;
	
	private User user;
	
	@Override
	public Integer getId() {
		throw new UnsupportedOperationException();
	}
	
	@Override
	public void setId(Integer id) {
		throw new UnsupportedOperationException();
	}
	
	public Attribute getAttribute() {
		return attribute;
	}
	
	public void setAttribute(Attribute attribute) {
		this.attribute = attribute;
	}
	
	public User getUser() {
		return user;
	}
	
	public void setUser(User user) {
		this.user = user;
	}
	
	@Override
	public boolean equals(Object object) {
		if (object instanceof AttributeAssignment) {
			AttributeAssignment attributeAssignment = (AttributeAssignment) object;
			Attribute attribute1 = attributeAssignment.getAttribute();
			User user1 = attributeAssignment.getUser();
			
			Attribute attribute2 = this.getAttribute();
			User user2 = this.getUser();
			
			if (attribute1 != null && user1 != null && attribute2 != null && user2 != null) {
				
				if (user1.equals(user2) && attribute1.equals(attribute2)) {
					return true;
				}
				
			}
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		if (this.getAttribute() == null && this.getUser() == null) {
			return super.hashCode();
		}
		
		int hashCode = 0;
		
		if (this.getUser() != null) {
			hashCode = this.getUser().hashCode();
		}
		
		if (this.getAttribute() != null) {
			hashCode += this.getAttribute().hashCode();
		}
		
		return hashCode;
	}
	
}
